<?php
/*
 *      oslistform.php
 *
 *      Copyright 2010 Vitaliy Rakitin <virak@ukr.net>
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
*/

require_once($_SERVER['DOCUMENT_ROOT']."/classes/GUI/osguitable.php");
require_once($_SERVER['DOCUMENT_ROOT']."/classes/GUI/osguitoolbar.php");
require_once($_SERVER['DOCUMENT_ROOT']."/classes/System/nwform.php");
require_once($_SERVER['DOCUMENT_ROOT']."/classes/GUI/nwmsg.php");

class osguitoolbar1 extends osguitoolbar {

	function onclick($p1, $p2) {
		switch ($p1) {
			case "insert":{
				$item = $this->object->add();
				$this->object->defaultitemform->show();
				break;
			}
			case "edit":{
				$item = $this->object->edit();
				$this->object->defaultitemform->show();
				break;
			}
		}
	}

}

class osguitable1 extends osguitable {

/*
	function ondblclick($p1, $p2) {
		parent::ondblclick($p1, $p2);
		$this->object->itemform($p1)->show();
	}
*/
}

class oslistform extends nwform {

	private $object;
	//private $dataset;
	protected $components = array();

	function __construct($object) {
		parent::__construct();
		$this->object = &$object;
		$this->caption = $this->object->name;
		$this->body = $this->defaultbody();
	}

	function close() {
		foreach ($this->components as $component) {
			$component->close();
		}
		parent::close();
	}

	function update() {
		$this->body = $this->defaultbody();
		parent::update();
	}

	function defaultbody() {
		$osguitoolbar = new osguitoolbar1(genuuid(), $this->object);
		$osguitoolbar->addbutton("insert", "Insert");
		$osguitoolbar->addbutton("edit", "Edit");
		$out = $osguitoolbar->get();
		$this->components[] = &$osguitoolbar;
		$osguitable = new osguitable1(genuuid(), $this->object);
		$out .= $osguitable->get();
		$this->components[] = &$osguitable;
		return $out;
	}
}
?>

